// 表单搜索
let oTxt = document.querySelector('.txt')
let oUl = document.querySelector('.list')



//给input绑定事件
oTxt.addEventListener('input', function () {
    // 清空内容
    oUl.innerHTML = ' '
    // 定义的函数必须是全局
    window.show = function (res) {
        let arr = res.g
        arr.forEach(function (ele, index) {
            let str = `<li class='next'><a onclick="displayData('${ele.q}')" onmouseover="aaa('${ele.q}')">${ele.q}</a></li>`
            let oLi = document.querySelector('.next')
            oUl.innerHTML += str
            // console.log(oLi)
            
            
        
        })
          
    }
   
   let s = document.createElement('script')
   s.src = `https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=1451,32439,32356,32328,32046,32395,32405,32115,26350,32503,22157&wd=${oTxt.value}&csor=2&pwd=cheng%20l&cb=show&_=1597281559085`
   document.body.appendChild(s)
})
function displayData(str){
    oTxt.value = str
}
function aaa(str){
    oTxt.value = str
}